package com.vast.ui.component.toolbar;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IViewSite;

import com.vast.metrix.recorder.bustraffic.Activator;
import com.vast.metrix.recorder.bustraffic.views.ViewPart;


public abstract class ToolBarAction extends AbstractActionBar {
	private final Action         startAction;
	private final Action         stopAction;
	private final Action         addAction;
	private final Action         deleteAction;
	public final Action          startChartAction;
	public final Action          pauseChartAction;
	public final Action          startRecordAction;
	public final Action          pauseRecordAction;
	public final Action          saveFileAction;
	
	
	public ToolBarAction(final IViewSite view) {
		super(view);
		startAction = new Action() {
			public void run() {
				//openConnection();
				startAction();
			}
		};
		startAction.setEnabled(true);
		startAction.setToolTipText("Establish Socket Server");
		startAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("START_ENABLED"));
		
		stopAction = new Action() {
			public void run() {
				//closeConnection();
				stopAction();
			}
		};
		stopAction.setEnabled(false);
		stopAction.setToolTipText("Close Socket Connection");
		stopAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("STOP_ENABLED"));
		
		addAction = new Action() {
			public void run() {
				addAction();
			}
		};
		addAction.setEnabled(true);
		addAction.setToolTipText("Add Line");
		addAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("ADD"));
		
		deleteAction = new Action() {
			public void run() {
				deleteAction();
			}
		};
		deleteAction.setEnabled(true);
		deleteAction.setToolTipText("Delete Line");
		deleteAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("DELETE"));
		
		startChartAction = new Action() {
			public void run() {
				startChartAction();
			}
		};
		startChartAction.setEnabled(true);
		startChartAction.setToolTipText("Start Preview");
		startChartAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("START_CHART"));
		
		pauseChartAction = new Action() {
			public void run() {
				pauseChartAction();
			}
		};
		pauseChartAction.setEnabled(true);
		pauseChartAction.setToolTipText("Stop Preview");
		pauseChartAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("PAUSE_CHART"));
		
		startRecordAction = new Action() {
			public void run() {
				startRecordAction();
			}
		};
		startRecordAction.setEnabled(true);
		startRecordAction.setToolTipText("Start Capture");
		startRecordAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("START_RECORD"));
		
		pauseRecordAction = new Action() {
			public void run() {
				pauseRecordAction();
			}
		};
		pauseRecordAction.setEnabled(true);
		pauseRecordAction.setToolTipText("Stop Capture");
		pauseRecordAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("PAUSE_RECORD"));
		
		saveFileAction = new Action() {
			public void run() {
				saveAction();
			}
		};
		saveFileAction.setEnabled(true);
		saveFileAction.setImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("SAVE_FILE"));
		saveFileAction.setText("Save as .csv");	
		
		toolbar.add(saveFileAction);
		toolbar.add(startRecordAction);
		toolbar.add(pauseRecordAction);
		toolbar.add(startChartAction);
		toolbar.add(pauseChartAction);
		toolbar.add(startAction);
		toolbar.add(stopAction);
		//toolbar.add(addAction);
		//toolbar.add(deleteAction);
	}

	public abstract void saveAction();
	public abstract void startAction();
	public abstract void stopAction();
	public abstract void addAction();
	public abstract void deleteAction();
	public abstract void startRecordAction();
	public abstract void pauseRecordAction();
	public abstract void startChartAction();
	public abstract void pauseChartAction();
	
	public void setStartActionEnable() {
		// TODO Auto-generated method stub
		startAction.setEnabled(true);
		stopAction.setEnabled(false);
		
	}

	public void setStopActionEnable() {
		// TODO Auto-generated method stub
		startAction.setEnabled(false);
		stopAction.setEnabled(true);
		setPauseChartActionEnable();
		setStartRecordActionEnable();
	}
	
	public void setStartChartActionEnable() {
		// TODO Auto-generated method stub
		startChartAction.setEnabled(true);
		pauseChartAction.setEnabled(false);
	}

	public void setPauseChartActionEnable() {
		// TODO Auto-generated method stub
		startChartAction.setEnabled(false);
		pauseChartAction.setEnabled(true);
		
	}
	
	public void setStartRecordActionEnable() {
		// TODO Auto-generated method stub
		startRecordAction.setEnabled(true);
		pauseRecordAction.setEnabled(false);
	}

	public void setPauseRecordActionEnable() {
		// TODO Auto-generated method stub
		startRecordAction.setEnabled(false);
		pauseRecordAction.setEnabled(true);
	}
	
	public void saveActionEnable(boolean isEnabled) {
		// TODO Auto-generated method stub
		saveFileAction.setEnabled(isEnabled);
	}

}
